define(function (require, exports, module) {
    var getSource = function (source, type) {
        const regex = new RegExp(`<${type}[^>]*>`);
        let openingTag = source.match(regex);
        if (!openingTag) return "";
        else openingTag = openingTag[0];
        return source.slice(
            source.indexOf(openingTag) + openingTag.length,
            source.lastIndexOf(`</${type}>`)
        );
    };
    var load_component = function (path) {
        var k = path.split("/");
        var j = k[k.length - 1].split(".");
        var component_name = j[0];
        // if (!window.vue_cache) {
        //     window.vue_cache = {};
        // }
        return function () {
            // if (window.vue_cache[component_name]) {
            //     return Promise.resolve(window.vue_cache[component_name]);
            // }
            return new Promise(function (resolve, reject) {
                require.async(path, function (data) {
                    var temp = getSource(data, "template");
                    var script = getSource(data, "script");
                    var codes = script.split("export default");
                    var code =
                        " define('" +
                        component_name +
                        "', function (require, exports, module) { " +
                        codes[0] +
                        " module.exports =  " +
                        codes[1] +
                        "  }); ";
                    new Function(code)();
                    require.async(component_name, function (b) {
                        if (temp) {
                            b.template = temp;
                        }
                        // window.vue_cache[component_name] = b;
                        resolve(b);
                    });
                });
            });
        };
    };
    module.exports = load_component;
});
